<?php
namespace app\api\controller\category;

// 底层控制器
use think\Controller;

//引入cookie
use think\Cookie;

use think\Request;

class Category extends Controller {
    // 构造函数

    public function __construct() {
        // 手动把父类的方法获取过来
        parent::__construct();

        $this->ProductModel = model( 'Product.Product' );
        $this->TypeModel = model( 'Product.Type' );
        $this->VipModel = model( 'Product.Vip' );
        $this->UserModel = model( 'User.User' );
    }

    // 分类主页

    public function index() {
        // 类别
        $typeList = $this->TypeModel->select();

        // 类别商品
        $productList = $this->TypeModel->select();

        // 组装商品
        foreach ( $productList as $item ) {
            $item[ 'product' ] = $this->ProductModel->where( [ 'typeid' => $item[ 'id' ] ] )->limit( 9 )->select();
        }

        // 推荐
        $recommendList = $this->ProductModel->where( [ 'flag' => 3 ] )->limit( 9 )->select();

        $data = [
            'typeList' => $typeList,
            'productList' => $productList,
            'recommendList' => $recommendList
        ];

        // 跳转界面
        $this->success( '获取数据成功！', null, $data );

    }
}
?>